//
//  UIBarButtonItem+Extension.m
//  smzdm_lib
//
//  Created by tom on 16/6/5.
//  Copyright © 2016年 sm. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+ (instancetype)barButtonItemImage:(NSString *)name highlightedImage:(NSString *)highlightedName target:(id)target action:(SEL)action {

    UIImage *image = [UIImage imageNamed:name];
    UIImage *hightlightedImage = [UIImage imageNamed:highlightedName];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, image.size.width, image.size.height );
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn setBackgroundImage:hightlightedImage forState:UIControlStateHighlighted];
    [btn addTarget:target action:action forControlEvents:
     UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [view addSubview:btn];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:view];
    return item ;
}

@end
